<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="misc.Configurations"%>
<%@page import="controller.RegisterController"%>
<%@page import="controller.RegisterController.RegError"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title><%=Configurations.title%>Register</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<h1>Registration</h1>
<%
RegisterController control = new RegisterController();
if(request.getParameter("username")!=null &&
    request.getParameter("password1")!=null && 
    request.getParameter("password2")!=null)
{
    String username = request.getParameter("username").trim();
    String password1 = request.getParameter("password1").trim();
    String password2 = request.getParameter("password2").trim();
    
    RegError status=control.registerThisUser(username,password1,password2);
    
    if(status==RegError.emptyinput)
    {
        %><div class="error">One or more inputs is empty!</div><%
    }
    else if(status==RegError.pwdnotequal)
    {
        %><div class="error">Passwords are not same!</div><%
    }
    else if(status==RegError.usernametaken)
    {
        %><div class="error">The username is taken already.</div><%
    }
    else if(status==RegError.unknown)
    {
        %><div class="error">Server encounters an unknown error. :-(</div><%
    }
    else
    {
        %><div class="success">You have registered successfully!</div><%
    }
}
%>
<form action="Register.jsp" method="post">
    <table border="0">
        <tr>
          <td>Username</td><td><input type="text" name="username"/></td>
        </tr>
        <tr>
          <td>Password</td><td><input type="password" name="password1"/></td>
        </tr>
        <tr>
          <td>Password<br/><small>(again)</small></td><td><input type="password" name="password2"/></td>
        </tr>
        <tr>
          <td colspan="2" align="right">
            <input type="submit" value="Register"/>
          </td>
        </tr>
    </table>
    <p><input type=button value="Close Window" onclick="javascript:window.close();" /></p>
</form>
</body>
</html>